home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / varia / silo.lha / silo / Bin.c next >
C/C++ Source or Header  |  1993-08-08  |  1KB  |  58 lines

  1. /* $Author: ecsv38 $ $Date: 90/08/21 14:45:38 $ $Revision: 1.1 $ */
  2. /* (c) S. Manoharan  sam@lfcs.edinburgh.ac.uk */
  3.  
  4. #include "Bin.h"
  5. #include "Sim.h"
  6.  
  7.  
  8. short
  9. Bin::take(Entity *bywho, const int event_type)
  10. {
  11.    bin_used = 1;
  12.  
  13.    if ( bywho == 0 )
  14.       cout << form("** Error: take by null entity\n");
  15.  
  16.    if ( available > 0 ) {
  17.       --available;
  18.       bywho->currentEvent(event_type);
  19.       return 1;
  20.    }
  21.    else {
  22.       bywho->currentEvent(event_type);
  23.       blockedQ.append(bywho);
  24.       return 0;
  25.    }
  26. }
  27.  
  28. void
  29. Bin::give()
  30. {
  31.    Entity *entity;
  32.  
  33.    if ( debug_level(1) ) {
  34.       cout << form("Releasing bin %s\n", bin_name);
  35.       cout << "\n---Begin{blockedQ}\n";
  36.       blockedQ.print();
  37.       cout << "\n---End{blockedQ}\n";
  38.    }
  39.  
  40.    if ( ( entity = blockedQ.get() ) != 0 ) {
  41.       Event *event = new Event(entity->currentEvent());
  42.       entity->schedule(0, event);
  43.    }
  44.    ++available;
  45. }
  46.  
  47. void
  48. Bin::set(const int sz)
  49. {
  50.    if ( bin_used ) {
  51.       cout << form("%s: bin already used. cannot set size\n",
  52.      bin_name);
  53.       exit(-1);
  54.    }
  55.    available = sz;
  56. }
  57.  
  58.